/*
 * 

 * 
 */
package com.cheche.dn.domain.admin;

import com.cheche.dn.common.base.BaseEntity;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.Sets;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotEmpty;

import javax.persistence.*;
import java.util.Set;

/**
 * Entity - 角色
 * @version 1.0
 */
@Entity
@Table(name = "role")
public class Role extends BaseEntity {
	private static final long serialVersionUID = -6614052029623997372L;

    public static final String NAME_PROPERTY_NAME = "name";

	/** 名称 */
	private String name;

	/** 是否内置 */
	private Boolean isSystem;

	/** 描述 */
	private String description;

	/** 权限 */
	private Set<Authority> authorities = Sets.newHashSet();

	/** 管理员 */
	private Set<Admin> admins = Sets.newHashSet();

	/**
	 * 获取名称
	 *
	 * @return 名称
	 */
	@JsonProperty
	@NotEmpty
	@Length(max = 50)
	@Column(nullable = false, unique = true)
	public String getName() {
		return name;
	}

	/**
	 * 设置名称
	 *
	 * @param name
	 *            名称
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * 获取是否内置
	 *
	 * @return 是否内置
	 */
	@JsonProperty
	@Column(nullable = false, updatable = false)
	public Boolean getIsSystem() {
		return isSystem;
	}

	/**
	 * 设置是否内置
	 *
	 * @param isSystem
	 *            是否内置
	 */
	public void setIsSystem(Boolean isSystem) {
		this.isSystem = isSystem;
	}

	/**
	 * 获取描述
	 *
	 * @return 描述
	 */
	@JsonProperty
	@NotEmpty
	@Length(max = 100)
	public String getDescription() {
		return description;
	}

	/**
	 * 设置描述
	 *
	 * @param description
	 *            描述
	 */
	public void setDescription(String description) {
		this.description = description;
	}

    /**
     * 获取权限
     *
     * @return 权限
     */
    @JsonProperty
    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "role_authority")
    public Set<Authority> getAuthorities() {
        return authorities;
    }

    /**
     * 设置权限
     *
     * @param authorities
     *            权限
     */
    public void setAuthorities(Set<Authority> authorities) {
        this.authorities = authorities;
    }

	/**
	 * 获取账号
	 *
	 * @return 账号
	 */
	@ManyToMany(mappedBy = "roles", fetch = FetchType.LAZY)
	public Set<Admin> getAdmins() {
		return admins;
	}

	public void setAdmins(Set<Admin> admins) {
		this.admins = admins;
	}

}